package com.xzk.ExpressInnWeb.util;

import com.xzk.ExpressInnWeb.bean.BootstrapTableExpress;
import com.xzk.ExpressInnWeb.bean.Express;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class ExUtil {

    public static String generateCode(){
        Random random = new Random();
        int code = random.nextInt(900000) + 100000;
        String codeStr = String.valueOf(code);
        return codeStr;
    }

    public static BootstrapTableExpress transferEx(Express ex){
        String intime = DateFormatUtil.format(ex.getIntime());
        String outtime = ex.getOuttime()==null?"未出库":DateFormatUtil.format(ex.getOuttime());
        String status = ex.getStatus()==0?"待取件":"已取件";
        String code = ex.getCode()==null?"无取件码":ex.getCode();
        return new BootstrapTableExpress(ex.getId(),
                ex.getEx_num(),ex.getUsername(),
                ex.getUserphone(),ex.getCompany(),
                code,intime,outtime,status,ex.getStaffphone());
    }

    public static List<BootstrapTableExpress> transferExList(List<Express> exList){
        List<BootstrapTableExpress> btExList = new ArrayList<>();
        for (Express ex: exList) {
            btExList.add(transferEx(ex));
        }
        return btExList;
    }

    public static Object[] transferExArray(Object[] exArr){
        Object[] result = new Object[exArr.length];
        for (int i=0;i<exArr.length;i++) {
            result[i] = transferEx((Express) exArr[i]);
        }
        return result;
    }

}
